package com.ruoyi.web.controller.gas;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.framework.web.exception.GlobalExceptionHandler;
import com.ruoyi.gas.domain.vo.IndustryMonthDanger;
import com.ruoyi.gas.domain.vo.MonthWarn;
import com.ruoyi.gas.domain.vo.StreetWarn;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gas.domain.GasWarnRectify;
import com.ruoyi.gas.service.IGasWarnRectifyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 隐患整改详情Controller
 *
 * @author ruoyi
 * @date 2024-01-18
 */
@RestController
@RequestMapping("/gas/rectifyAll")
public class GasWarnRectifyController extends BaseController
{
    @Autowired
    private IGasWarnRectifyService gasWarnRectifyService;

    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    /**
     * 查询隐患整改详情列表
     */
    @PreAuthorize("@ss.hasPermi('gas:rectifyAll:list')")
    @GetMapping("/list")
    public TableDataInfo list(GasWarnRectify gasWarnRectify)
    {
        startPage();
        List<GasWarnRectify> list = gasWarnRectifyService.selectGasWarnRectifyList(gasWarnRectify);
        return getDataTable(list);
    }

    /**
     * 导出隐患整改详情列表
     */
    @PreAuthorize("@ss.hasPermi('gas:rectifyAll:export')")
    @Log(title = "隐患整改详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GasWarnRectify gasWarnRectify)
    {
        List<GasWarnRectify> list = gasWarnRectifyService.selectGasWarnRectifyList(gasWarnRectify);
        ExcelUtil<GasWarnRectify> util = new ExcelUtil<GasWarnRectify>(GasWarnRectify.class);
        util.exportExcel(response, list, "隐患整改详情数据");
    }

    /**
     * 获取隐患整改详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('gas:rectifyAll:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gasWarnRectifyService.selectGasWarnRectifyById(id));
    }

    /**
     * 新增隐患整改详情
     */
    @PreAuthorize("@ss.hasPermi('gas:rectifyAll:add')")
    @Log(title = "隐患整改详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GasWarnRectify gasWarnRectify)
    {
        return toAjax(gasWarnRectifyService.insertGasWarnRectify(gasWarnRectify));
    }

    /**
     * 修改隐患整改详情
     */
    @PreAuthorize("@ss.hasPermi('gas:rectifyAll:edit')")
    @Log(title = "隐患整改详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GasWarnRectify gasWarnRectify)
    {
        return toAjax(gasWarnRectifyService.updateGasWarnRectify(gasWarnRectify));
    }

    /**
     * 删除隐患整改详情
     */
    @PreAuthorize("@ss.hasPermi('gas:rectifyAll:remove')")
    @Log(title = "隐患整改详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gasWarnRectifyService.deleteGasWarnRectifyByIds(ids));
    }

    /**
     * 导出本月各行业隐患排查数据
     */
    @PostMapping("/exportMonthDangerByIndustry")
    public void exportMonthDangerByIndustry(HttpServletResponse response)
    {
        List<IndustryMonthDanger> list = gasWarnRectifyService.selectMonthDangerByIndustry();
        if (list!=null&&list.size()>0){
            IndustryMonthDanger sum = gasWarnRectifyService.selectMonthDangerSumByIndustry();
            list.add(sum);
        }
        ExcelUtil<IndustryMonthDanger> util = new ExcelUtil<IndustryMonthDanger>(IndustryMonthDanger.class);
        util.exportExcel(response, list, "本月各行业隐患排查数据");
    }

    /**
     * 导出本月企业预警情况
     */
    @PostMapping("/exportWarnByMonth")
    public void exportWarnByMonth(HttpServletResponse response)
    {
        List<MonthWarn> list = gasWarnRectifyService.selectWarnByMonthList();
        ExcelUtil<MonthWarn> util = new ExcelUtil<MonthWarn>(MonthWarn.class);
        util.exportExcel(response, list, "本月企业预警情况");
    }

    /**
     * 导出本月企业预警情况
     */
    @PostMapping("/exportStreetWarn")
    public void exportStreetWarn(HttpServletResponse response)
    {
        List<StreetWarn> list = gasWarnRectifyService.selectStreetWarnList();
        ExcelUtil<StreetWarn> util = new ExcelUtil<StreetWarn>(StreetWarn.class);
        util.exportExcel(response, list, "街道预警情况");
    }
}
